﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace B.S.XZYData.Infrastructure.Interface
{
    /// <summary>
    /// 基础操作接口层
    /// </summary>
    public interface IBaseRepository<T> where T : class, new()
    {
        /// <summary>
        /// 根据主键查询
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>返回model实体</returns>
        Task<T> GetValue(long id);
        
        /// <summary>
        /// 查询所有数据
        /// </summary>
        /// <returns>返回所有数据</returns>
        ISugarQueryable<T> GetAll();

        /// <summary>
        /// 根据条件查询数据
        /// </summary>
        /// <param name="expression">查询条件</param>
        /// <returns>返回查询结果</returns>
        Task<List<T>> GetAllAsync(Expression<Func<T, bool>> expression);
        
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="t">实体</param>
        /// <returns>返回成功或失败</returns>
        Task<int> CreateAsync(T t);
        
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="t">实体</param>
        /// <returns>返回成功或失败</returns>
        Task<int> UpdateAsync(T t);
        
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>返回成功或失败</returns>
        Task<int> DeleteAsync(long id);
        
        /// <summary>
        /// 批量新增
        /// </summary>
        /// <param name="entities">实体列表</param>
        /// <returns>返回成功或失败</returns>
        Task<int> CreateBatchAsync(List<T> entities);
        
        /// <summary>
        /// 批量修改
        /// </summary>
        /// <param name="entities">实体列表</param>
        /// <returns>返回成功或失败</returns>
        Task<int> UpdateBatchAsync(List<T> entities);
        
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="entities">实体列表</param>
        /// <returns>返回成功或失败</returns>
        Task<int> DeleteBatchAsync(List<T> entities);
        
        /// <summary>
        /// 开始事务
        /// </summary>
        /// <returns></returns>
        Task BeginTranAsync();
        
        /// <summary>
        /// 提交事务
        /// </summary>
        /// <returns></returns>
        Task CommitTranAsync();
        
        /// <summary>
        /// 回滚事务
        /// </summary>
        /// <returns></returns>
        Task RollbackTranAsync();
    }
}
